<template>
	<view class="container">
		<view class="header">
			<image class="headerBg" src="https://puhuishequ.oss-cn-beijing.aliyuncs.com/attach/2020-07/076a9202007061021275354.png"
			 mode=""></image>
			<uni-nav-bar fixed="ture" statusBar="true" @clickLeft="back" title="会员权益" :color="navColor" leftIcon="back"
			 :background="navBG">
			</uni-nav-bar>
			<view class="carousel-section">
				<swiper :current="current" class="carousel" circular @change="change">
					<swiper-item v-for="(item, index) in cardList" :key="index" class="carousel-item">
						<view class="item">
							<image lazy-load :src="item.image" />
							<view class="vipInfo" v-if="userLevel == 0">
								<text class="a">开通{{item.name}}</text>
								<text class="b">即可享受以下全部权力</text>
							</view>
							<view class="vipInfo" v-else-if="userLevel == 1&&index == 0">
								<text class="a">尊贵的{{item.name}}</text>
								<text class="b">已享受以下全部权力</text>
							</view>
							<view class="vipInfo" v-else-if="userLevel == 1&&index == 1">
								<text class="a">开通{{item.name}}</text>
								<text class="b">即可享受以下全部权力</text>
							</view>
							<view class="vipInfo" v-else-if="userLevel == 2&&index == 0">
								<text class="a">开通{{item.name}}</text>
								<text class="b">即可享受以下全部权力</text>
							</view>
							<view class="vipInfo" v-else-if="userLevel == 2&&index == 1">
								<text class="a">尊贵的{{item.name}}</text>
								<text class="b">已享受以下全部权力</text>
							</view>
						</view>
					</swiper-item>
				</swiper>
			</view>
		</view>
		<view class="qyBg">
			<view class="dots" v-if="!interests">
				<view :class="current == 0?'act':''" class="a"></view>
				<view :class="current == 1?'act':''" class="a"></view>
			</view>
			<image :src="cardList[current].benefit_image" mode="widthFix"></image>
		</view>
		<view class="btnBox" @tap="btnTo">
			<image src="https://inclusivecommunity.oss-cn-chengdu.aliyuncs.com/attach/2020-08/7bb64202008211138331317.png" mode=""></image>
			<text>{{btnText}}</text>
		</view>
	</view>
</template>

<script>
	import {
		cardInfo,
	} from "@/api/user.js"
	import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
	export default {
		components: {
			uniNavBar
		},
		data() {
			return {
				btnType: 0,
				navColor: '#fff',
				navBG: 'inherit',
				current: 0,
				cardList: [
					{benefit_image: ''},
					{benefit_image: ''}
				],
				btnText: '',
				userLevel: -1,
				interests: false
			}
		},
		onLoad(option) {
			if (option.level) {
				this.interests = true
				this.current = Number(option.level) - 1
			}
			cardInfo().then(res => {
				this.cardList = res.data.cardInfo
			})
		},
		onShow() {
			this.userLevel = uni.getStorageSync("userInfo").level
			if (this.userLevel == 0) {
				this.btnText = '购买会员'
				this.btnType = 0
			} else if (this.userLevel == 1 || this.userLevel == 2) {
				this.btnText = '会员中心'
				this.btnType = 1
			}
		},
		onPageScroll(e) {
			this.navBG = "rgba(255,255,255," + e.scrollTop / 100 + ')'
			if (e.scrollTop > 0) {
				this.navColor = '#333'
			} else {
				this.navColor = '#fff'
			}
		},
		methods: {
			back() {
				uni.navigateBack({

				})
			},
			change(e) {
				this.current = e.target.current
				if (this.userLevel == 0) {
					this.btnText = '购买会员'
					this.btnType = 0
				} else if (this.userLevel == 1 && this.current == 0) {
					this.btnText = '会员中心'
					this.btnType = 1
				} else if (this.userLevel == 1 && this.current == 1) {
					this.btnText = '升级会员'
					this.btnType = 2
				} else if (this.userLevel == 2) {
					this.btnText = '会员中心'
					this.btnType = 1
				}
			},
			btnTo() {
				if (this.interests) {
					uni.navigateBack({
						
					})
				} else {
					if (this.btnType == 0) {
						uni.navigateTo({
							url: "./buyVip"
						})
					} else if (this.btnType == 1) {
						uni.navigateTo({
							url: "./vipRights"
						})
					} else if (this.btnType == 2) {
						uni.navigateTo({
							url: "./buyVip?type=upgrade"
						})
					}
				}
			}
		}
	};
</script>
<style lang="scss" scoped>
	.container {
		.header {
			position: relative;
			height: 576rpx;

			.headerBg {
				position: absolute;
				width: 100%;
				height: 576rpx;
			}

			.carousel-section {
				position: relative;
				padding: 100rpx 0 0;

				.carousel {
					width: 100%;
					height: 400rpx;

					.carousel-item {
						padding: 0 30rpx;
						box-sizing: border-box;
						width: 100%;
						height: 100%;
						overflow: hidden;

						.item {
							width: 100%;
							height: 100%;

							image {
								width: 100%;
								height: 100%;
								border-radius: 10rpx;
							}

							.vipInfo {
								position: absolute;
								color: #8B7D5C;
								left: 66rpx;
								top: 60rpx;
								display: flex;
								flex-direction: column;

								.a {
									font-size: 40rpx;
									font-weight: bold;
									margin-bottom: 20rpx;
								}

								.b {
									font-size: 24rpx;
									height: 50rpx;
									line-height: 50rpx;
									padding: 0 20rpx;
									border: 1rpx solid #8B7D5C;
									border-radius: 25rpx;
								}
							}
						}
					}
				}
			}
		}

		.qyBg {
			position: relative;

			.dots {
				position: absolute;
				left: 0;
				top: -80rpx;
				display: flex;
				width: 100%;
				justify-content: center;

				.a {
					margin-right: 10rpx;
					width: 30rpx;
					height: 6rpx;
					border-radius: 3rpx;
					background-color: #fff;
				}

				.act {
					background-color: #8B7D5C;
				}
			}

			image {
				width: 100%;
				margin-top: -120rpx;
			}
		}

		.btnBox {
			margin-top: 50rpx;
			padding-bottom: 60rpx;
			padding-bottom: calc(env(safe-area-inset-bottom) + 60rpx);
			width: 100%;
			height: 150rpx;
			position: relative;

			image {
				position: absolute;
				width: 100%;
				height: 150rpx;
			}

			text {
				display: block;
				width: 100%;
				font-size: 36rpx;
				color: #8B7D5C;
				font-weight: bold;
				letter-spacing: 4rpx;
				text-align: center;
				line-height: 180rpx;
				position: relative;
				z-index: 2;
			}
		}
	}
</style>
